/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lottoapp;

import java.util.Set;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;

/**
 *
 * @author Mark Dechamps
 */
public class Record {

    public SimpleStringProperty name = new SimpleStringProperty();
    public SimpleIntegerProperty nr1 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr2 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr3 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr4 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr5 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr6 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr7 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr8 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr9 = new SimpleIntegerProperty();
    public SimpleIntegerProperty nr10 = new SimpleIntegerProperty();
    public SimpleBooleanProperty plays = new SimpleBooleanProperty();

    public String getName() {
        return name.get();
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public int getNr1() {
        return nr1.get();
    }

    public void setNr1(int nr1) {
        this.nr1.set(nr1);
    }

    public int getNr2() {
        return nr2.get();
    }

    public void setNr2(int nr2) {
        this.nr2.set(nr2);
    }

    public int getNr3() {
        return nr3.get();
    }

    public void setNr3(int nr3) {
        this.nr3.set(nr3);
    }

    public int getNr4() {
        return nr4.get();
    }

    public void setNr4(int nr4) {
        this.nr4.set(nr4);
    }

    public int getNr5() {
        return nr5.get();
    }

    public void setNr5(int nr5) {
        this.nr5.set(nr5);
    }

    public int getNr6() {
        return nr6.get();
    }

    public void setNr6(int nr6) {
        this.nr6.set(nr6);
    }

    public int getNr7() {
        return nr7.get();
    }

    public void setNr7(int nr7) {
        this.nr7.set(nr7);
    }

    public int getNr8() {
        return nr8.get();
    }

    public void setNr8(int nr8) {
        this.nr8.set(nr8);
    }

    public int getNr9() {
        return nr9.get();
    }

    public void setNr9(int nr9) {
        this.nr9.set(nr9);
    }

    public int getNr10() {
        return nr10.get();
    }

    public void setNr10(int nr10) {
        this.nr10.set(nr10);
    }

    public boolean isPlays() {
        return plays.get();
    }

    public void setPlays(boolean plays) {
        this.plays.set(plays);
    }

    static Record fromPlayer(Player player) {
        Integer[] nrs = player.getNumbers().toArray(new Integer[]{});
        return fromPlayerAndArray(player, nrs);

    }

    static Record fromPlayerWithResults(Player player, Set<Integer> remainingNumbers) {
        Integer[] nrs = remainingNumbers.toArray(new Integer[]{});
        return fromPlayerAndArray(player, nrs);
    }

    private static void set(SimpleIntegerProperty field, int i, Integer[] nrs) {
        if (nrs.length - 1 >= i) {
            field.set(nrs[i]);
        }
    }

    private static Record fromPlayerAndArray(Player player, Integer[] nrs) {
        Record r = new Record();
        r.setName(player.getFirstname() + " " + player.getLastname());

        set(r.nr1, 0, nrs);
        set(r.nr2, 1, nrs);
        set(r.nr3, 2, nrs);
        set(r.nr4, 3, nrs);
        set(r.nr5, 4, nrs);
        set(r.nr6, 5, nrs);
        set(r.nr7, 6, nrs);
        set(r.nr8, 7, nrs);
        set(r.nr9, 8, nrs);
        set(r.nr10, 9, nrs);
        return r;
    }

    @Override
    public String toString() {
        return "Record{" + "name=" + name + ", nr1=" + nr1 + ", nr2=" + nr2 + ", nr3=" + nr3 + ", nr4=" + nr4 + ", nr5=" + nr5 + ", nr6=" + nr6 + ", nr7=" + nr7 + ", nr8=" + nr8 + ", nr9=" + nr9 + ", nr10=" + nr10 + ", plays=" + plays + '}';
    }
}
